package lzzy;

import java.io.*;

public class TestDataStream {
    public static void main(String[] args) throws IOException {
        try(
            // 为文件创建输出流 temp.dat
             DataOutputStream output =
                new DataOutputStream(new FileOutputStream("temp.dat"));
        )  {
            // 将学生考试成绩写入文件
            output.writeUTF("John");
            output.writeDouble(85.5);
            output.writeUTF("Jim");
            output.writeDouble(185.5);
            output.writeUTF("George");
            output.writeDouble(105.25);
        }

        try(
            // 为文件创建输入流 temp.dat
             DataInputStream input =
                new DataInputStream(new FileInputStream("temp.dat"));
        )  {
            // 从文件中读取学生考试成绩
            System.out.println(input.readUTF() + " " + input.readDouble());
            System.out.println(input.readUTF() + " " + input.readDouble());
            System.out.println(input.readUTF() + " " + input.readDouble());
        }
    }
}
